/*
	Copyright (C) 2013 Pontificia Universidad Catolica del Peru
	contact: http://avatar.inf.pucp.edu.pe/realidad-aumentada/
	address contact: Av. Universitaria 1801, San Miguel, Lima-Peru.
	
	This file is part of UbicAR PUCP.

	This program is free software: you can redistribute it and/or modify
	it under the terms of the GNU General Public License as published by
	the Free Software Foundation, either version 3 of the License, or
	(at your option) any later version.

	This program is distributed in the hope that it will be useful,
	but WITHOUT ANY WARRANTY; without even the implied warranty of
	MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
	GNU General Public License for more details.

	You should have received a copy of the GNU General Public License
	along with This program.  If not, see <http://www.gnu.org/licenses/>.
*/
/*
	Authors: Alvaro Roger Agüero Sánchez, Rodolfo Javier Galvez Meza
	Pontificia Universidad Catolica del Peru
	Departamento de Ingeniería
*/

package org.grupoavatar.guiaubicua.auxiliares;

//import android.R;
import com.google.android.gms.common.ConnectionResult;
import com.google.android.gms.common.GooglePlayServicesUtil;

import android.content.Context;
import android.content.res.Configuration;
import android.graphics.Bitmap;
import android.graphics.Canvas;
import android.graphics.Bitmap.Config;
import android.graphics.drawable.BitmapDrawable;
import android.graphics.drawable.Drawable;

public class Utiles {
	
	private final static String DOMINIO_ORIGINAL = "http://ubicar.inf.pucp.edu.pe/";
	private final static String DOMINIO_TEMP = "http://200.16.7.112/movil/api/";
	//private final static String TEMP = "http://172.17.20.127:8080/";
	private final static String DOMINIO = DOMINIO_ORIGINAL;
	private final static String URL_PUNTOS = DOMINIO + "Ubicua/resource/ws/punto";
	private final static String URL_PUNTOS_TEMP = DOMINIO_TEMP + "CO_test_puntos/";
	//private final static String LOCAL_PUNTOS = "file://sdcard/guiaUbicuaPUCP/InternalJSON.json";
	private final static String URL_COMENTARIOS = DOMINIO + "Ubicua/punto_comment/";
	private final static String URL_ENCUESTA = DOMINIO + "Ubicua/resource/ws/encuesta/";
	private final static String URL_CONSULTAR_RATING = DOMINIO + "Ubicua/resource/ws/votacion/punto/";
	private final static String URL_ENVIAR_RATING = DOMINIO + "Ubicua/resource/ws/votacion/";
	private final static String URL_ENVIAR_RESULTADOS_ENCUESTA = DOMINIO + "Ubicua/resource/ws/resultado/";
	private final static String URL_CONSULTAR_INTERACCION = DOMINIO + "Ubicua/resource/ws/interaccion/";
	private final static String URL_CONSULTAR_USUARIO = DOMINIO + "Ubicua/resource/ws/usuario/";
	
	private final static String URL_PLAY_STORE = "http://bit.ly/YefDk5";
	
	public static boolean isTablet(Context context) {
	    boolean xlarge = ((context.getResources().getConfiguration().screenLayout & Configuration.SCREENLAYOUT_SIZE_MASK) == 4);
	    boolean large = ((context.getResources().getConfiguration().screenLayout & Configuration.SCREENLAYOUT_SIZE_MASK) == Configuration.SCREENLAYOUT_SIZE_LARGE);
	    return (xlarge || large);
	}
	
	public static String ShowURL() {
		return "http://ubicar.inf.pucp.edu.pe/Ubicua/punto/";
	}
	
	public static String getEncuestaURL(String idPoi) {
		String url = URL_ENCUESTA + idPoi + "/" + Usuario.id_usuario;
		return url;
	}
	
	public static String getPuntosURL() {
		return URL_PUNTOS_TEMP;
	}
	
	public static String getConsultarRatingURL(String idPoi) {
		String url = URL_CONSULTAR_RATING + idPoi + "/" + Usuario.id_usuario;
		return url;
	}
	
	public static String getEnviarRatingURL() {
		return URL_ENVIAR_RATING;
	}
	
	public static String getEnviarResultadosEncuestaURL() {
		return URL_ENVIAR_RESULTADOS_ENCUESTA;
	}
	
	public static String getConsultarInteraccionURL(int idInteraccion) {
		String url = URL_CONSULTAR_INTERACCION + idInteraccion; 
		return url;
	}
	
	public static String getConsultarUsuarioURL() {
		return URL_CONSULTAR_USUARIO;
	}
	
	public static String getComentariosURL() {
		return URL_COMENTARIOS;
	}
	
	public static String compartirAplicacion() {
		return "Te recomiendo descargar UbicAR PUCP de la PlayStore: " + URL_PLAY_STORE;
	}
	
	public static boolean TieneGooglePlayServices(Context context) {
		int status = GooglePlayServicesUtil.isGooglePlayServicesAvailable(context);
		boolean flag = false;
		if(status != ConnectionResult.SUCCESS) { 
			flag = false; 
		} else {
			flag = true;
		}
		return flag;
		
	}
	
	public static Bitmap drawableToBitmap (Drawable drawable) {
	    if (drawable instanceof BitmapDrawable) {
	        return ((BitmapDrawable)drawable).getBitmap();
	    }

	    Bitmap bitmap = Bitmap.createBitmap(drawable.getIntrinsicWidth(), drawable.getIntrinsicHeight(), Config.ARGB_8888);
	    Canvas canvas = new Canvas(bitmap); 
	    drawable.setBounds(0, 0, canvas.getWidth(), canvas.getHeight());
	    drawable.draw(canvas);

	    return bitmap;
//	    return adjustOpacity(bitmap, 20);
	}
}
